﻿using Prism.Events;
using Prism.Services.Dialogs;

namespace TiaoTiaoCode.AutoUpdate.ServerUI.Splashs
{
    /// <summary>
    /// Splash窗口类
    /// </summary>
    public class SplashManager
    {
        readonly IDialogService _dialogSer;
        readonly IEventAggregator _eventAggr;

        public SplashManager(IDialogService dialogService, IEventAggregator eventAggregator)
        {
            _dialogSer = dialogService;
            _eventAggr = eventAggregator;
        }

        /// <summary>
        /// 显示Loading窗口
        /// </summary>
        /// <param name="loadingContent"></param>
        public void ShowLoading(string loadingContent)
        {
            var drp = new DialogParameters();
            drp.Add("LoadingContent", loadingContent);

            _dialogSer.Show("LoadingWindow", drp, dr => { });
            _eventAggr.GetEvent<LoadingDialogPubSubEvent>().Publish(new LoadingDialogPubSubEventMessage(loadingContent, SplashCommand.Show));
        }

        /// <summary>
        /// 更新Loading窗口显示内容
        /// </summary>
        /// <param name="loadingContent"></param>
        public void UpdateLoadingContent(string loadingContent)
        {
            _eventAggr.GetEvent<LoadingDialogPubSubEvent>().Publish(new LoadingDialogPubSubEventMessage(loadingContent, SplashCommand.ReWriteContent));
        }

        /// <summary>
        /// 隐藏Loading窗口
        /// </summary>
        public void HideLoading()
        {
            _eventAggr.GetEvent<LoadingDialogPubSubEvent>().Publish(new LoadingDialogPubSubEventMessage(string.Empty, SplashCommand.Hide));
        }
    }
}
